package com.hcy.performancepro.controller.performanceTool;

import com.fuled.test.tool_config.DisableUtil;
import com.hcy.performancepro.bo.performanceTool.RecordControllerBo;
import com.hcy.performancepro.bo.performanceTool.RecordServiceBo;
import com.hcy.performancepro.po.performanceTool.RecordService;
import com.hcy.performancepro.service.performanceTool.PerformanceToolServiceService;
import com.hcy.performancepro.util.ResultData;
import com.hcy.performancepro.vo.performanceTool.RecordServiceVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/performanceService")
@DisableUtil
@RequiredArgsConstructor
public class PerformanceToolServiceController {
    private final PerformanceToolServiceService performanceToolServiceService;

    @PostMapping("/page")
    public ResultData<Object> page(@RequestParam Integer currentPage, @RequestParam Integer pageSize,@RequestBody RecordServiceBo recordServiceBo){
        List<RecordService> list = performanceToolServiceService.sarchlist(currentPage, pageSize,recordServiceBo);
        List<RecordServiceVo> listVo = new ArrayList<>();
        if(list != null && !list.isEmpty()) {
            for (RecordService obj : list) {
                RecordServiceVo vo = new RecordServiceVo();
                BeanUtils.copyProperties(obj, vo);
                listVo.add(vo);
            }
        }
        return ResultData.ok(listVo);
    }

    @GetMapping("/count")
    public ResultData<Object> count(RecordServiceBo recordServiceBo){
        return ResultData.ok(performanceToolServiceService.countNumber(recordServiceBo));
    }
}